<?php

/**
 * The RectangleFilter, this filter creates a rectangle on the Image
 *
 * @version $Revision v1.00$
 * @author Bryan Spirit & Mark Kazemier
 */
class RectangleFilter extends Filter
{
    private $m_oPointUL;
    private $m_oPointRD;
    
    private $m_oColor;
    
    /**
     * Constructs a new Rectangle filter. The rectangle has as upper left point $oPointUL
     * and as right down point $oPointRD. The color of the rectangle will be $oColor.
     *
     * @param Filter The optional nested filter
     * @param Point The upper left point of the rectangle
     * @param Point The right down point of the rectangle
     * @param Color The color of the rectangle
     */
    public function __construct(Filter $oFilter = null, Point $oPointUL, Point $oPointRD, Color $oColor)
    {
        parent::__construct($oFilter);
        
        $this->m_oPointUL = $oPointUL;
        $this->m_oPointRD = $oPointRD;
        
        $this->m_oColor = $oColor;
    }
    
    public function filter(Image $oImage)
    {
        if(!imagerectangle($oImage->getResource(), $this->m_oPointUL->getX(), $this->m_oPointUL->getY(),
                                                   $this->m_oPointRD->getX(), $this->m_oPointRD->getX(),
                                                   $this->m_oColor->getColor()))
            throw new FilterDrawException('The Rectangle could not be drawed');
        
        parent::filter($oImage);
    }
}
